<?php
/**
 * Pop up Image Header
 *
 * @package page
 * @copyright Copyright 2005-2006 breakmyzencart.com
 * @copyright Portions Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: header_php.php,v 1.4 2006/04/11 22:00:55 tim Exp $
 */
/**
 * Header code file for the product-larger-images popup window
 *
 */

// This should be first line of the script:
  $zco_notifier->notify('NOTIFY_HEADER_START_POPUP_IMAGES_ADDITIONAL');

 $_SESSION['navigation']->remove_current_page();
  
  if($_GET['categories_id']==''){
  	exit();
  }
  
   $action = (isset($_GET['action']) ? $_GET['action'] : '');
    $action = 'getcategories';
   switch ($action){
   	   case 'getcategories':
   	   	 //查找下级栏目
   	   	    $parent_id= (isset($_GET['categories_id']) ? $_GET['categories_id'] : '');
	   	   	$categories_query = "select c.categories_id, cd.categories_name,c.categories_type
	                         from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
	                         where parent_id = '" . (int)$parent_id . "'
	                         and c.categories_id = cd.categories_id
	                         and c.categories_status=1
	                         and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
	                         order by sort_order, cd.categories_name";
	
	        $categories = $db->Execute($categories_query);
	        $dataString  ='';
	        $category_type_array=array('b'=>0,'s'=>0,'m'=>0,'p'=>0);
	        while (!$categories->EOF) {
			      $dataString .='{"value":"'. $categories->fields['categories_id'].'","name":"'. $categories->fields['categories_name'].'"},';
			      if($categories->fields['categories_type']!=''){
				      foreach ($category_type_array as $k=>$v)
				      {
				      	if($k==$categories->fields['categories_type'])
				      	{
				      		$category_type_array[$k]++;
				      	} 	
				      }
			      }
			      $categories->MoveNext();
			}
		if(strlen($dataString)>0){//如果有子目录；
			//去掉最后一个 ,
			 $dataString=substr($dataString,0,-1);	
			
	   	   $max_key=array_search(max($category_type_array),$category_type_array);
	   	   if($category_type_array[$max_key]==0){
	   	   	  //栏目下的所有 子类都没有定义 栏目类型 
	   	   	  $dataProductType="SubCategoryType";
	   	   }elseif($max_key=='b'){
	   	   	  $dataProductType="Brand";
	   	   }elseif($max_key=='s'){
	   	   	  $dataProductType="Series";
	   	   }elseif($max_key=='m'){
	   	   	  $dataProductType="Model";
	   	   }elseif($max_key=='p'){
	   	   	  $dataProductType="ProductType"; 	
	   	   }else{
	   	   	  $dataProductType="SubCategoryType";
	   	   }
	  
	   	   echo 'var data'.$dataProductType.'=['.$dataString.'];';
		}
   	   	
   	   break;
   	   
   	   case 'getcatetypes':
   	   	//查找下级栏目外  还查找他各级子栏目的属性
   	   	
  	
  	   break;
  	   
   }

//echo 'var dataProductType = [
//{"value":"0","name":"All Products"},
//{"value":"700","name":"Adapters/Splitters"},
//{"value":"1000","name":"Universal Items"}];
//';
//
//echo 'var dataBrand = [
//{"value":"6","name":"Apple"},{"value":"10","name":"Audiovox"},
//{"value":"124","name":"UTStarcom"},{"value":"128","name":"Vodafone"}];';
//

  $zco_notifier->notify('NOTIFY_HEADER_END_POPUP_IMAGES');
 